package com.martian.common.exception;

import com.martian.common.enums.BaseErrorCodeEnum;

/**
 * @author martian
 * @version V1.0.0
 * @Description
 * @date 2023-03-24 14:06
 */

public class SysException extends RuntimeException {

    protected int code;

    public SysException() {
    }

    public SysException(String message) {
        super(message);
    }

    public SysException(BaseErrorCodeEnum codeEnum, Object... args) {
        super(String.format(codeEnum.getMessage(), args));
        this.code = codeEnum.getCode();
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    @Override
    public String toString() {
        return "{" +
                "\"code\":" + code +
                ",\"message\":\"" + getMessage() +
                "\"}";
    }
}
